//
//  userAccount.swift
//  weibo20
//
//  Created by mac on 16/1/24.
//  Copyright © 2016年 tingyuyisheng. All rights reserved.
//

import UIKit

/// 用户账户信息
/// - see: [http://open.weibo.com/wiki/OAuth2/access_token](http://open.weibo.com/wiki/OAuth2/access_token)
class userAccount: NSObject {

	/// 用于调用access_token，接口获取授权后的access token。
	var access_token: String?

	/// access_token的生命周期，单位是秒数。
	var expires_in: NSTimeInterval = 0 {
		didSet {
			// 当过期日期一旦被设置的时候,就立即设置expires_date
			expires_date = NSDate(timeIntervalSinceNow: expires_in)
		}
	}

	/// 当前授权用户的UID。
	var uid: String?

	/// token的过期时间
	var expires_date: NSDate?

	init(dict : [String : AnyObject]) {
		super.init()
		setValuesForKeysWithDictionary(dict)
	}

	override func setValue(value: AnyObject?, forUndefinedKey key: String) { }

	override var description : String {
		let keys = ["access_token", "expires_in", "uid", "name", "avatar_large", "expires_date"]
		return dictionaryWithValuesForKeys(keys).description
	}
}
